﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using db = DataContext;

namespace LogicLibrary
{
	/// <summary>
	/// 首页大图
	/// </summary>
	public class IndexPictures
	{
		public static List<db.IndexPictures> GetList()
		{
			using (db.DbDataContext context = new db.DbDataContext())
			{
				return context.IndexPictures.OrderBy(x => x.Sort).ToList();
			}
		}
		public static void Add(db.IndexPictures picture)
		{
			using (db.DbDataContext context = new db.DbDataContext())
			{
				context.IndexPictures.InsertOnSubmit(picture);
				context.SubmitChanges();
			}
		}
		public static void Delete(int id)
		{
			using (db.DbDataContext context = new db.DbDataContext())
			{
				context.IndexPictures.DeleteOnSubmit(context.IndexPictures.Single(x => x.Id == id));
				context.SubmitChanges();
			}
		}
		public static void SaveOrders(List<KeyValuePair<int, int>> orders)
		{
			using (db.DbDataContext context = new db.DbDataContext())
			{
				orders.ForEach(x => context.IndexPictures.Single(y => y.Id == x.Key).Sort = x.Value);
				context.SubmitChanges();
			}
		}
	}
}
